import 'package:flutter/material.dart';
import 'package:flutter_learn_demo/page_cache/keep_alive_wrapper.dart';

class KeepAliveTest extends StatefulWidget {

  const KeepAliveTest({super.key});

  @override
  State<StatefulWidget> createState() => KeepAliveTestState();

}

class KeepAliveTestState extends State<KeepAliveTest> {

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
       appBar: AppBar(
         title: const Text('Keep Alive Test'),
         backgroundColor: Colors.cyan,
       ),
       body: ListView.separated(itemBuilder: (context, index) {
          return KeepAliveWrapper(
                keepAlive: true,
                child: DefineListItem(index: index),
            );
       },
       itemCount: 60,
       separatorBuilder: (BuildContext context, int index) {
         double dividerHeight = 2;
         //分割线Divider  height属性值需与thickness相同  否则不能填充满
         return Divider(color: Colors.deepOrangeAccent,height: dividerHeight,thickness: dividerHeight,);
        },
       ),
    );
  }
}

class DefineListItem extends StatefulWidget {

  const DefineListItem({Key? key,required this.index}):super(key: key);

  final int index;

  @override
  State<StatefulWidget> createState() => _DefineListItemState();

}

class _DefineListItemState extends State<DefineListItem> {

  @override
  Widget build(BuildContext context) {
     return ListTile(
          title: Text('widget:${widget.index}'),
     );
  }

  @override
  void dispose() {
    super.dispose();
    print('widget000:${widget.index}');
  }
}